perm filename EAUX2B.2[EAL,HE]2 blob sn#701199 filedate 1983-03-24 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	{$NOMAIN	Editor: Cursor moving routines }
C00024 00003	{ Externally defined routines from elsewhere: }
C00025 00004	(* Cursor moving routines: nextStmnt, lastStmnt, parentStmnt *)
C00043 ENDMK
C⊗;
{$NOMAIN	Editor: Cursor moving routines }

const

	(* Constants from EDIT *)
      	maxLines = 28;		(* smaller on the 11 than on the 10 *)
      	maxPPLines = 18;
      	maxBpts = 25;
      	maxTBpts = 20;	(* max could be exceeded by huge case stmnt *)
	listinglength = 2000;	(* Length of Listingarray *)

(* Random type declarations for OMSI/SAIL compatibility *)

type

  byte = 0..255;	(* doesn't really belong here, but... *)
  ascii = char; 
  atext = text;

{ Define all the pointer types here }

strngp = ↑strng;
statementp = ↑statement;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
tokenp = ↑token;
reswordp = ↑resword;
pdbp = ↑pdb;
envheaderp = ↑envheader;
enventryp = ↑enventry;
environp = ↑environment;
cmoncbp = ↑cmoncb;
linerecp = ↑linerec;
cursorpp = ↑cursorp;	{Ron's style, not mine}

(* This one is used whenever a pointer is needed for which the 	*)
(* definition is missing from this file; naturally, all 	*)
(* pointers use the same space 					*)

dump = ↑integer;

(* datatype definitions *)

datatypes = (pconstype, varitype, svaltype, vectype, rottype, transtype,
	     frametype, eventtype, strngtype, labeltype, proctype, arraytype,
	     reftype, valtype, cmontype, nulltype, undeftype,
	     dimensiontype, mactype, macargtype, freevartype);

scalar = real;

cstring = packed array [1..10] of ascii;
c4str = packed array [1..4] of ascii;
c5str = packed array [1..5] of ascii;
c20str = packed array [1..20] of ascii;
linestr = packed array [1..130] of ascii;

strng = record
	  next: strngp;
	  ch: cstring;
	end;


(* statement definitions *)

stmntypes = (progtype, blocktype, coblocktype, endtype, coendtype,
		fortype, iftype, whiletype, untiltype, casetype,
		calltype, returntype,
		printtype, prompttype, pausetype, aborttype, assigntype,
		signaltype, waittype, enabletype, disabletype, cmtype,
		affixtype, unfixtype,
		movetype, operatetype, opentype, closetype, centertype,
		stoptype, retrytype,
		requiretype, definetype, macrotype, commenttype, dimdeftype,
		setbasetype, wristtype, tovaltype, declaretype, emptytype);
		(* more??? *)

statement = packed record
		next, last: statementp; (* ↑ to lexical tokens? *)
		stlab: varidefp;
		exprs: nodep;	(* any expressions used by this statement *)
		nlines: integer;
		bpt: boolean;
		case stype: stmntypes of

    progtype:	    (pcode: statementp; errors: integer);
    blocktype,
    declaretype,
    endtype,
    coendtype:	    (bcode, bparent: statementp; blkid: identp;
			level, numvars: 0..255; variables: varidefp);
    coblocktype:    (threads: nodep; nthreads: integer; cblkid: identp);
    fortype:	    (forvar, initial, step, final: nodep; fbody: statementp);
    casetype:	    (index: nodep; range, ncases: integer; caselist: nodep);
    untiltype:	    (cond: nodep; body: statementp);
    iftype:	    (icond: nodep; thn, els: statementp);
    aborttype:	    (plist: nodep; debugLev: integer);
    cmtype:	    (oncond: nodep; conclusion: statementp;
			deferCm, exprCm: boolean; cdef: varidefp);
		end;

(* auxiliary definitions: variable, etc. *)

varidef = packed record
	    next,dnext: varidefp;
	    name: identp;
	    level: 0..255;	(* environment level *)
	    offset: 0..255;	(* environment offset *)
	    dtype: varidefp;	(* to hold the dimension info *)
	    tbits: 0..15;  (* special type bits: array = 1, proc = 2, ref = 4 & ? *)
	    dbits: 0..15;	(* for use by debugger/interpreter *)
	    case vtype: datatypes of
  arraytype:  (a: nodep);
  proctype:   (p: nodep);
  labeltype,
  cmontype:   (s: statementp);
  mactype:    (mdef: statementp);
  macargtype: (marg: tokenp);
  pconstype:  (c: nodep);
  dimensiontype: (dim: nodep);
	  end;

(* definition of the ubiquitous NODE record *)

nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
		deprnode, viaptnode, apprnode, destnode, durnode,
		sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
		arrivalnode, departingnode,
		ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
		calcnode, arraydefnode, bnddefnode, bndvalnode,
		waitlistnode, procdefnode, tlistnode, dimnode, commentnode);

exprtypes =  (	svalop,					(* scalar operators *)
		sltop, sleop, seqop, sgeop, sgtop, sneop,	(* relations *)
		notop, orop, xorop, andop, eqvop,		(* logical *)
		saddop, ssubop, smulop, sdivop, snegop, sabsop, (* scalar ops *)
		sexpop, maxop, minop, intop, idivop, modop,
		sqrtop, logop, expop, timeop,			(* functions *)
		sinop, cosop, tanop, asinop, acosop, atan2op,	(* trig *)
		vdotop, vmagnop, tmagnop,
		vecop,					(* vector operators *)
		vmakeop, unitvop, vaddop, vsubop, crossvop, vnegop,
		svmulop, vsmulop, vsdivop, tvmulop, wrtop,
		tposop, taxisop,
		transop,				(* trans operators *)
		tmakeop, torientop, ttmulop, tvaddop, tvsubop, tinvrtop,
		vsaxwrop, constrop, ftofop, deproachop, fmakeop, vmkfrcop,
		ioop,					(* i/o operators *)
		queryop, inscalarop,
		specop,					(* special operators *)
		arefop, callop, grinchop, macroop, vmop, adcop, dacop,
		badop,
		addop, subop, negop, mulop, divop, absop); (* for parsing *)

leaftypes = pconstype..strngtype;

reltypes = sltop..sgtop;
forcetypes = (force,absforce,torque,abstorque,angvelocity);

node = record
	next: nodep;
	case ntype: nodetypes of
    exprnode:	(op: exprtypes; arg1, arg2, arg3: nodep; elength: integer);
    leafnode:	(case ltype: leaftypes of
	varitype:  (vari: varidefp; vid: identp);
	pconstype: (cname: varidefp; pcval: nodep);
	svaltype:  (s: scalar; wid: integer);
	vectype:   (v: dump);
	transtype: (t: dump);
	strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
    listnode:	(lval: nodep);
    clistnode:	(cval: integer; stmnt: statementp; clast: nodep);
    colistnode:	(prev: nodep; cstmnt: statementp);
    errornode:	(eexpr: nodep);
    calcnode: 	(rigid, frame1: boolean; other: dump; case tvarp: boolean of 
		    false: (tval: dump); true: (tvar: enventryp) );
    arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
    bnddefnode:	(lower, upper: nodep);
    bndvalnode:	(lb, ub, mult: integer);
    waitlistnode: (who: pdbp; when: integer);
    procdefnode:(ptype: datatypes; level: 0..255;
		    pname, paramlist: varidefp; body: statementp);
    tlistnode:	(tok: tokenp);
    dimnode:	(time, distance, angle, dforce: integer);
	end;

(* records for parser: ident, token, resword *)

ident = record
	    next: identp;
	    length: integer;
	    name: strngp;
	    predefined: varidefp;
	  end;


tokentypes = (reswdtype, identtype, constype, comnttype, delimtype, labeldeftype,
		macpartype);

constypes = svaltype..strngtype;

reswdtypes = (stmnttype, filtype, clsetype, decltype, optype, edittype);

filtypes = (abouttype,alongtype,attype,bytype,defertype,dotype,elsetype,
		errmodestype,fromtype,handtype,intype,nonrigidlytype,rigidlytype,
		sourcefiletype,steptype,thentype,totype,untltype,viatype,
		withtype,worldtype,zeroedtype,oftype,wheretype,nowaittype,
		ontype,offtype,ppsizetype,collecttype,alltype,lextype);

clsetypes = (approachtype,arrivaltype,departuretype,departingtype,durationtype,
		errortype,forcetype,forceframetype,forcewristtype,gathertype,
		nildeproachtype,nonullingtype,nullingtype,stiffnesstype,
		torquetype,velocitytype,wobbletype,
		cwtype,ccwtype,stopwaittimetype,angularvelocitytype,
		fxtype,fytype,fztype,mxtype,mytype,mztype,
		t1type,t2type,t3type,t4type,t5type,t6type,tbltype);

edittypes = (getcmd,savecmd,insertcmd,renamecmd,startcmd,gocmd,proceedcmd,
		stepcmd,sstepcmd,nstepcmd,gstepcmd,executecmd,setcmd,tracecmd,
		breakcmd,unbreakcmd,tbreakcmd,definecmd,markcmd,unmarkcmd,
		popcmd);

token = record
	  next: tokenp;
	  case ttype: tokentypes of
constype:   (cons: nodep);
comnttype:  (len: integer; str: strngp);
delimtype:  (ch: ascii);
reswdtype:  (case rtype: reswdtypes of
	stmnttype: (stmnt: stmntypes);
	filtype:   (filler: filtypes);
	clsetype:  (clause: clsetypes);
	decltype:  (decl: datatypes);
	optype:	   (op: exprtypes);
	edittype:  (ed: edittypes) );
identtype:  (id: identp);
labeldeftype: (lab: varidefp);
macpartype: (mpar: varidefp);
	end;


resword = record
	  next: reswordp;
	  length: integer;
	  name: strngp;
	  case rtype: reswdtypes of
	stmnttype:  (stmnt: stmntypes);
	filtype:    (filler: filtypes);
	clsetype:   (clause: clsetypes);
	decltype:   (decl: datatypes);
	optype:	    (op: exprtypes);
	edittype:  (ed: edittypes);
	  end;

(* process descriptor blocks & environment record definitions *)

queuetypes = (nullqueue,nowrunning,runqueue,inputqueue,eventqueue,sleepqueue,
		forcewait,devicewait,joinwait,proccall);

pdb = packed record
	nextpdb,next: pdbp;	(* for list of all/active pdb's *)
	level: 0..255;		(* lexical level *)
	mode: 0..255;		(* expression/statement/sub-statement *)
	priority: 0..255;
	status: queuetypes;	(* what are we doing *)
	env: envheaderp;
	spc: statementp;	(* current statement *)
	epc: nodep;		(* current expression (if any) *)
	sp: nodep;		(* intermediate value stack *)
	cm: cmoncbp;		(* if we're a cmon point to our definition *)
	mech: dump;		(* current device being used *)
	linenum: integer;	(* used by editor/debugger *)
	 case procp: boolean of	(* true if we're a procedure *)
true:  (opdb: pdbp;		(* pdb to restore when procedure exits *)
	pdef: nodep);		(* procedure definition node *)
false: (evt: dump;		(* event to signal when process goes away *)
	sdef: statementp);	(* first statement where process was defined *)
      end;


envheader = packed record
	      parent: envheaderp;
	      env: array [0..4] of environp;
	      varcnt: 0..255;		(* # of variables in use ??? *)
		case procp: boolean of  (* true if we're a procedure *)
	true: (proc: nodep);
	false:(block: statementp);
	    end;


enventry = record
	    case etype: datatypes of
  svaltype:  (s: scalar);
  vectype:   (v: dump);
  transtype: (t: dump);
  frametype: (f: dump);
  eventtype: (evt: dump);
  strngtype: (length: integer; str: strngp);
  cmontype:  (c: cmoncbp);
  proctype:  (p: nodep; penv: envheaderp);
  reftype:   (r: enventryp);
  arraytype: (a: envheaderp; bnds: nodep);
	   end;


environment = record
		next: environp;
		vals: array [0..9] of enventryp;
	      end;


cmoncb = record
	   running, enabled: boolean;		(* cmon's status *)
	   cmon: statementp;
	   pdb: pdbp;
	   evt: dump;
	   fbits: integer;			(* bits for force sensing *)
	   oldcmon: cmoncbp;			(* for debugger *)
	 end;

(* print related records: *)

cursorp = record
	  cline,ind: integer;
	  case stmntp: boolean of
  true:    (st: statementp);
  false:   (nd: nodep);
	 end;

linerec = record
	next: linerecp;
	start,length: integer
       end;

listingarray = packed array [0..listinglength] of ascii;


(* Global variables *)

var 
	(* From ALMAIN *)
    b:boolean;		
    ch:ascii;
    ltime: real;

	(* From PARSE *)
    reswords: array [0..26] of reswordp;
    idents: array [0..26] of identp;
    macrostack: array [1..10] of tokenp;
    curmacstack: array [1..10] of varidefp;
    macrodepth: integer;
    curchar, maxchar, curline: integer;
    curBlock,newDeclarations: statementp;
    curProc: varidefp;
    pnode: nodep;
    nodim, distancedim, timedim, angledim,
      forcedim, torquedim, veldim, angveldim: varidefp;
    fvstiffdim, mvstiffdim: nodep;
(*  filedepth: integer;
    curpage: integer;
    sysVars,unVars: varidefp;
    errcount: integer;
    outerBlock: statementp;
    curVariable: varidefp;
    curMotion: statementp;
    endOk,coendOk: integer;
    moveLevel: integer;
    curErrhandler, curCmon: statementp;	*)
    d1: array[1..13] of dump;
    endOfLine, backup, expandmacros, flushcomments, dimCheck: boolean;
(*  semiseen, shownline: boolean;
    eofError: boolean;
    inMove,inCoblock: boolean;	*)
    d2,d3,d4,d5,d6: boolean;
    curtoken: token;
    file1,file2,file3,file4,file5: atext;
    line: linestr;

	(* From INTERP *)
    curInt, activeInts, readQueue, allPdbs: pdbp;
(*  curEnv, sysEnv: envheaderp;
    clkQueue: nodep;
    allEvents: dump;
    STLevel: integer;		
    etime: integer;		
    curtime: integer; 		
    stime: integer;		
    msg: dump;			
    inputp: integer;		
    debugLevel: integer;	*)
    d10: array[1..11] of integer;
    tSingleThreadMode: boolean;
    resched, running, escapeI, singleThreadMode: boolean;
    msgp: boolean;		(* flag set if any messages pending *)
    inputReady: boolean;
    inputLine: array [1..20] of ascii;

	(* From EDIT *)
    lines: array [1..maxLines] of linerecp; 
    ppLines: array [1..maxPPLines] of linerecp;	
    marks: array [1..20] of integer;
    cursorStack: array [1..15] of cursorp;
    bpts: array [1..maxBpts] of statementp;
    tbpts: array [1..maxTBpts] of statementp;
    debugPdbs: array [0..10] of pdbp;
    screenheight,dispHeight: integer;
    ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
    lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
    firstDline,topDline,botDline,firstLine,lastLine: integer;
    freeLines,oldLines: linerecp;
    findStmnt: statementp;
    nbpts,ntbpts: integer;
    eCurInt: pdbp;
    dProg: statementp;	
    smartTerminal: boolean; 
    setUp,setExpr,setCursor,dontPrint,outFilep,newVarOk,collect: boolean;
    backUp: boolean;			
    eSingleThreadMode: boolean;	
    listing: listingarray;
    lbuf: array [1..160] of ascii;
    ppBuf: array [1..100] of ascii;
    outFile: atext;
    curToken: token;			

	(* Various device & variable pointers *)
    speedfactor: enventryp;
    barm: dump;

	(* Various constant pointers *)
    xhat,yhat,zhat,nilvect: dump;
    niltrans: dump;
    bpark, ypark, gpark, rpark: dump;		(* arm park positions *)

{ Externally defined routines from elsewhere: }

	(* From EAUX1A *)
procedure pushStmnt(s: statementp; indent: integer);		external;
procedure pushNode(n: nodep);					external;

(* Cursor moving routines: nextStmnt, lastStmnt, parentStmnt *)

(* move down i statements *)
procedure nextStmnt(i: integer; downp: boolean);  external;
procedure nextStmnt;
 var j: integer; s: statementp; upp,b: boolean; n: nodep;
 begin
 j := 0;
 b := downp;
 repeat
  upp := false;
  with cursorStack[cursor] do
   if b and stmntp then
     begin				(* try to move down a level *)
     curLine := cline;
     case st↑.stype of
blocktype: pushStmnt(st↑.bcode,2);
coblocktype: begin
	     pushNode(st↑.threads);
	     pushStmnt(st↑.threads↑.cstmnt,1);
	     end;
casetype:  begin
	   curLine := curLine + 1;
	   n := st↑.caselist;
	   if st↑.range < 0 then
	     begin				(* skip over label(s) *)
	     b := true;
	     while b and (n↑.next <> nil) do
	      begin
	      if n↑.stmnt = n↑.next↑.stmnt then
		begin
		curLine := curLine + 1;
		n := n↑.next;
		end
	       else b := false;
	      end;
	     end;
	   pushNode(n);
	   if st↑.range < 0 then curLine := curLine + 1;
	   pushStmnt(n↑.stmnt,2);
	   end;
fortype:   pushStmnt(st↑.fbody,2);
iftype:	   if (fieldNum = 2) then
	     if st↑.els <> nil then pushStmnt(st↑.els,2) else upp := true
	    else pushStmnt(st↑.thn,2);
whiletype,
untiltype: pushStmnt(st↑.body,2);
cmtype:	   pushStmnt(st↑.conclusion,2);
otherwise  upp := true;
      end;
     end
    else if cursorStack[cursor-1].stmntp then
     begin				(* block, if, other statements *)
     s := cursorStack[cursor-1].st;
     if s↑.stype = blocktype then
       begin				(* move down to next stmnt in block *)
       if st↑.next <> nil then
	 begin					(* down to next stmnt *)
	 if (st↑.stype = aborttype) and (s↑.debugLev > 0) then st := st↑.next;
	 cline := cline + st↑.nlines;
	 st := st↑.next;
	 if (st↑.stype = declaretype) and (st↑.numvars = 1) then
	   with st↑.variables↑ do
	    if (tbits = 2) and (p <> nil) then
	      begin
	      curLine := cline;
	      pushNode(p);
	      cursorStack[cursor].cline := curLine;
	      end;
	 end
	else
	 if cursor = 3 then j := i		(* can't go any further *)
	  else
	   begin				(* up we go *)
	   upp := true;
	   cursor := cursor - 1;
	   curBlock := s↑.bparent;
	   end;
       end
      else if b and (s↑.stype = declaretype) then
       begin			(* move down into procedure definition *)
       curLine := cline;
       pushStmnt(s↑.variables↑.p↑.body,2);
       end
      else if s↑.stype = iftype then
       begin				(* move to ELSE or next stmnt *)
       if (s↑.thn = st) and (s↑.els <> nil) then
	 begin					(* down to ELSE *)
	 cline := cline + st↑.nlines + 1;
	 st := s↑.els;
	 end
	else
	 begin upp := true; cursor := cursor - 1; end;	(* up we go *)
       end
      else if s↑.stype = casetype then
       begin					(* move to next stmnt *)
       if stmntp then
	 begin upp := true; cursor := cursor - 1; end	(* up we go *)
	else
	 begin
	 n := nd;				(* label where we are now *)
	 curLine := cline;
	 b := true;
	 while b and (n↑.next <> nil) do
	  begin
	  if n↑.stmnt = n↑.next↑.stmnt then
	    begin
	    curLine := curLine + 1;
	    n := n↑.next;
	    end
	   else b := false;
	  end;
	 nd := n;
	 cline := curLine;
	 pushStmnt(n↑.stmnt,2);
	 end
       end
      else if cursor = 2 then j := i		(* can't go anywhere else *)
      else
       begin upp := true; cursor := cursor - 1; end;	(* up we go *)
     end
    else
     begin				(* coblock, case, clause *)
     with cursorStack[cursor-1].nd↑ do
      if ntype = clistnode then
	begin
	cline := cline + stmnt↑.nlines;
	cursorStack[cursor-1].cline := cline;
	if next <> nil then
	  begin
	  n := next;
	  b := true;
	  while b and (n↑.next <> nil) do
	   begin			(* check for multiple labels *)
	   if n↑.stmnt = n↑.next↑.stmnt then
	     begin
	     cline := cline + 1;
	     n := n↑.next;
	     end
	    else b := false;
	   end;
	  cursorStack[cursor-1].cline := cline;
	  cursorStack[cursor-1].nd := n;
	  st := n↑.stmnt;
	  if cursorStack[cursor-2].st↑.range < 0 then
	   cline := cline + 1;			(* account for label line *)
	  end
	 else
	  begin
	  cursor := cursor - 2;			(* roll back to CASE stmnt *)
	  curLine := cline - 1;
	  pushStmnt(stmnt↑.next,1);		(* and move to END *)
	  end
	end
       else if ntype = colistnode then
	begin
	cline := cline + cstmnt↑.nlines;
	cursorStack[cursor-1].cline := cline;
	if next <> nil then
	  begin				(* move down to next thread *)
	  st := next↑.cstmnt;
	  cursorStack[cursor-1].nd := next;
	  end
	 else
	  with cursorStack[cursor-1] do
	   begin				(* move to COEND *)
	   cursor := cursor - 1;
	   st := cstmnt↑.next;
	   stmntp := true;
	   end;
	end
       else	(* ??? maybe we want to descend into motion clauses ??? *)
	begin upp := true; cursor := cursor - 2; end;	(* up we go *)
     end;
  if upp then b := false
   else
    begin
    b := downp;
    j := j + 1;
    end;
 until j >= i;
 cursorLine := cursorStack[cursor].cline;
 end;

(* move up i statements *)
procedure lastStmnt(i: integer; downp: boolean);   external;
procedure lastStmnt;
 var j: integer; s: statementp; godownp,b: boolean; n: nodep;
 begin
 j := 0;
 repeat
  godownp := downp;
  with cursorStack[cursor] do
   begin
   j := j + 1;
   if st↑.stype = blocktype then curBlock := st↑.bparent;
   if stmntp and (st↑.stype = iftype) and (fieldNum = 2) then
     begin
     curLine := cline;
     pushStmnt(st↑.thn,2);	(* move up to the THEN *)
     end
    else if cursorStack[cursor-1].stmntp then
     begin
     s := cursorStack[cursor-1].st;
     case s↑.stype of
progtype:   begin			(* not much to do here *)
	    j := i;
	    godownp := false;
	    if st↑.stype = blocktype then curBlock := st else curBlock := nil;
	    end;
blocktype:  begin
	    st := st↑.last;		(* move up a statement *)
	    if (st↑.stype = aborttype) and (s↑.debugLev > 0) then st := st↑.last;
	    if (st = nil) or (st = s) then
	      begin				(* back to BEGIN *)
	      cursor := cursor - 1;
	      godownp := false;
	      end
	     else
	      begin
	      cline := cline - st↑.nlines;
	      if (st↑.stype = declaretype) and (st↑.numvars = 1) then
		with st↑.variables↑ do
		 if (tbits = 2) and (p <> nil) then
		   begin
		   curLine := cline;
		   pushNode(p);
		   cursorStack[cursor].cline := curLine;
		   if godownp then pushStmnt(p↑.body,2);
		   end;
	      end
	    end;
coblocktype:begin
	    n := s↑.threads;
	    while n↑.next <> nil do n := n↑.next;  (* move to last thread *)
	    cursor := cursor - 1;
	    curLine := cline - n↑.cstmnt↑.nlines - 1;
	    pushNode(n);
	    pushStmnt(n↑.cstmnt,1);
	    end;
casetype:   begin
	    if stmntp then
	      begin				(* move to last case *)
	      n := s↑.caselist;
	      while n↑.next <> nil do n := n↑.next;
	      cursor := cursor - 1;
	      curLine := cline - n↑.stmnt↑.nlines - 1;
	      pushNode(n);
	      pushStmnt(n↑.stmnt,2);
	      end
	     else
	      begin				(* move to previous case *)
	      n := nd;				(* label where we are now *)
	      curLine := cline - 1;
	      b := true;
	      while b and (n↑.clast <> nil) do
	       begin
	       if n↑.stmnt = n↑.clast↑.stmnt then curLine := curLine - 1
		else b := false;
	       n := n↑.clast;
	       end;
	      if n <> nil then
		begin
		nd := n;
		curLine := curLine - n↑.stmnt↑.nlines;
		cline := curLine;
		pushStmnt(n↑.stmnt,2);
		end
	       else
		begin				(* back to CASE stmnt *)
		cursor := cursor - 1;
		godownp := false;
		end;
	      end;
	    end;
iftype:	    begin
	    if s↑.els = st then
	      begin				(*  back to THEN *)
	      st := s↑.thn;
	      cline := cline - s↑.thn↑.nlines - 1;
	      end
	     else
	      begin				(* back to the IF *)
	      cursor := cursor - 1;
	      godownp := false;
	      end;
	    end;
otherwise   begin
	    cursor := cursor - 1;		(* up a level *)
	    godownp := false;
	    if s↑.stype = declaretype then j := j - 1;	(* proc def *)
	    end;
      end
     end
    else
     with cursorStack[cursor-1].nd↑ do		(* coblock, case, clause *)
      if ntype = clistnode then
	if clast <> nil then
	  begin
	  if cursorStack[cursor-2].st↑.range < 0 then
	   cline := cline - 1;			(* account for label line *)
	  n := cursorStack[cursor-1].nd;
	  b := true;
	  while b and (n↑.clast <> nil) do
	   begin			(* check for multiple labels *)
	   if n↑.stmnt = n↑.clast↑.stmnt then cline := cline - 1
	    else b := false;
	   n := n↑.clast;
	   end;
	  if n = nil then
	    begin
	    cursor := cursor - 2;		(* up a level to CASE *)
	    godownp := false;
	    end
	   else
	    begin
	    cline := cline - n↑.stmnt↑.nlines;
	    cursorStack[cursor-1].cline := cline;
	    cursorStack[cursor-1].nd := n;
	    st := n↑.stmnt;
	    end
	  end
	 else
	  begin
	  cursor := cursor - 2;			(* up a level to CASE *)
	  godownp := false;
	  end
       else if ntype = colistnode then
	if prev <> nil then
	  begin				(* move up to last thread *)
	  cline := cline - prev↑.cstmnt↑.nlines;
	  st := prev↑.cstmnt;
	  cursorStack[cursor-1].cline := cline;
	  cursorStack[cursor-1].nd := prev;
	  end
	 else
	  begin
	  cursor := cursor - 2;		(* up a level to COBEGIN *)
	  godownp := false;
	  end
       else
	begin				(*  move us up a level *)
	repeat cursor := cursor - 1 until cursorStack[cursor].stmntp;
	if cursor = 1 then 
	  begin
	  cursor := 2;			(* back to the top *)
	  godownp := false;
	  j := i;
	  end;
	end;
   end;
  while godownp do		(* move to bottom stmnt in current stmnt *)
   with cursorStack[cursor] do
    begin				(* try to move down a level *)
    curLine := cline;
    case st↑.stype of
blocktype:   begin
	     curLine := curLine + st↑.nlines - 2;
	     s := st↑.bcode;
	     while s↑.next <> nil do s := s↑.next;
	     pushStmnt(s,0);				(* move to END *)
	     godownp := false;
	     end;
coblocktype: begin
	     curLine := curLine + st↑.nlines - 2;
	     pushStmnt(st↑.threads↑.cstmnt↑.next,1);	(* move to COEND *)
	     godownp := false;
	     end;
casetype:    begin
	     curLine := curLine + st↑.nlines - 2;
	     pushStmnt(st↑.caselist↑.stmnt↑.next,1);	(* move to END *)
	     godownp := false;
	     end;
fortype:     pushStmnt(st↑.fbody,2);			(* move to body *)
iftype:	     begin
	     if st↑.els <> nil then
	       begin
	       curLine := curLine + st↑.thn↑.nlines + 1;
	       pushStmnt(st↑.els,2);
	       end
	      else pushStmnt(st↑.thn,2);
	     end;
whiletype,
untiltype:   pushStmnt(st↑.body,2);
cmtype:	     pushStmnt(st↑.conclusion,2);
otherwise    godownp := false;
     end;
    end;
 until j >= i;
 cursorLine := cursorStack[cursor].cline;
 end;

(* move up to n levels *)
procedure parentStmnt(n: integer);		 external;
procedure parentStmnt;
 var i,j: integer;
 begin
 for j := 1 to n do
  begin
  i := cursor - 1;
  while not cursorStack[i].stmntp do i := i - 1;
  if i = 1 then cursor := 2		(* back to the top *)
   else cursor := i;			(* back to parent *)
  end;
 with cursorStack[cursor] do
  if st↑.stype = blocktype then curBlock := st;
 cursorLine := cursorStack[cursor].cline;
 end;